home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_weap_ailaser.cog < prev    next >
Text File  |  1999-11-15  |  5KB  |  195 lines

  1. # Jones 3D Cog Script
  2. #
  3. # weap_AILaser.cog
  4. #
  5. # Generic Weapon Class Cog for AI Laser fire. Individual AI's
  6. # can set a customized version of this in their weapon template.
  7. #
  8. # [MDR]
  9. #
  10. # (C) 1999 LucasArts Entertainment Company LLC. All Rights Reserved
  11. #
  12. # ===================================================================
  13.  
  14. symbols
  15.  
  16. message        startup
  17. message        fire
  18. message        touched
  19. message        removed
  20.  
  21. # ************************* SUBROUTINES *************************
  22. flex    GetBulletAndLaserRef                            local
  23. flex    CreateImpactGlow                                local
  24.  
  25. # ************************* TEMPLATES ***************************
  26. template    tpl_laserGlow=redflash                        local
  27. template    tpl_laserHit=+robot_blast                    local
  28. material    mat_beam=gen_a4sfx_rbbeam_b.mat                local
  29. material    mat_hit=gen_a4sprite_rbblast.mat            local
  30.  
  31. # ************************* CUSTOM PARAMETERS *******************
  32. vector        vec_glowStartSize                            local
  33. vector        vec_glowEndSize                                local
  34.  
  35. # ************************* MISC LOCAL VARS *********************
  36. thing        t_shooter                                    local
  37. thing        t_victim                                    local
  38. thing        t_bullet                                    local
  39. thing        t_LaserGlow                                    local
  40. thing        t_beam                                        local
  41. flex        f_beamSize                                    local
  42. flex        f_beamTime                                    local
  43.  
  44. thing        t_glowImpact                                local
  45. int            b_hitThing                                    local
  46. vector        vec_pos                                        local
  47. vector        vec_dir                                        local
  48.  
  49. end
  50.  
  51.  
  52. # ===================================================================
  53. code
  54.  
  55. # ...................................................................
  56. startup:
  57.  
  58.     vec_glowStartSize    = VectorSet(0.2, 0.2, 0.4);
  59.     vec_glowEndSize        = VectorSet(0.5, 0.5, 0.8);
  60.     b_hitThing            = 0;
  61.  
  62.     return;
  63.  
  64.  
  65. # ...................................................................
  66. fire:
  67.  
  68.     t_shooter    = GetSourceRef();
  69.     t_bullet    = GetSenderRef();
  70.  
  71.     if ( t_bullet < 0 ) return;                                            # Bad bullet?  Bail...
  72.  
  73.     f_beamTime    = GetLifeleft(t_bullet);                                # Beam lifetime is lifetime of bullet
  74.     f_beamSize    = GetThingMoveSize(t_bullet);                            # Beam size is 5 * size of bullet
  75.     f_beamSize    = 5 * f_beamSize;
  76.  
  77.     vec_pos        = VectorAdd( GetThingPos(t_shooter), VectorTransformToOrient(t_shooter, GetThingFireoffset(t_shooter)) );
  78.  
  79.     t_LaserGlow    = CreateThingAtPos(tpl_laserGlow, FindNewSectorFromThing(t_shooter, vec_pos), vec_pos, '0 0 0');
  80.     if ( t_LaserGlow > -1 )
  81.     {
  82.         SetLifeLeft(t_LaserGlow, f_beamTime);
  83.         AnimateSpriteSize(t_LaserGlow, vec_glowStartSize, vec_glowEndSize, f_beamTime);
  84.     }
  85.  
  86.     t_beam = CreatePolylineThing(t_bullet, t_LaserGlow, '0 0 0', mat_beam, f_beamSize, f_beamSize, f_beamTime);
  87.     if ( t_beam > -1 )
  88.     {
  89.         SetThingUserData(t_bullet, t_beam);                                # Save off beam handle
  90.         AttachThingToThingEx(t_beam, t_bullet, 0x08);
  91.  
  92.         PlaySoundClass(t_bullet, 106);                                    # Play a SITHSOUNDCLASS_FIRE1 sound on bullet
  93.     }
  94.  
  95.     return;
  96.  
  97.  
  98. # ...................................................................
  99. touched:
  100.  
  101.     t_victim = GetSourceRef();
  102.  
  103.     call GetBulletAndLaserRef;
  104.  
  105.     if ( t_beam > -1 )                                                        # Attach beam to victim
  106.     {
  107.         vec_pos = VectorSet( 0, 0, VectorZ(GetThingEyeOffset(t_victim))/2 );
  108.         vec_pos = VectorAdd(GetThingPos(t_victim), vec_pos);
  109.  
  110.         SetThingPosEX(t_beam, vec_pos, GetThingSector(t_victim));
  111.         AttachThingToThingEx(t_beam, t_victim, 0x08);
  112.     }
  113.  
  114.     SetThingUserData(t_bullet, 0);                                            # bullet forgets beam handle
  115.  
  116.     b_hitThing = 1;
  117.     call CreateImpactGlow;
  118.  
  119.     return;
  120.  
  121.  
  122. # ...................................................................
  123. removed:
  124.  
  125.     call GetBulletAndLaserRef;
  126.  
  127.     if ( (t_bullet > -1) && (t_beam > -1) )                                    # Extend beam to final bullet pos
  128.     {
  129.         SetThingPosEX(t_beam, GetThingPos(t_bullet), GetThingSector(t_bullet));
  130.         call CreateImpactGlow;
  131.     }
  132.  
  133.     return;
  134.  
  135.  
  136. # ===================================================================
  137. #    Subroutines
  138. # ===================================================================
  139.  
  140. # ...................................................................
  141. GetBulletAndLaserRef:
  142.  
  143.     t_bullet = GetSenderRef();
  144.     if ( (t_bullet > -1) && (GetThingType(t_bullet) == 3) )                    # Check for SITH_THING_WEAPON
  145.     {
  146.         t_beam = GetThingUserData(t_bullet);
  147.         if ( (t_beam > 0) && (GetThingType(t_beam) == 14) )                    # Check for SITH_THING_POLYLINE
  148.         {
  149.             return;
  150.         }
  151.     }
  152.     
  153.     t_beam = -1;
  154.  
  155.     return;
  156.  
  157.  
  158. # ...................................................................
  159. # t_bullet and possibly t_victim & vec_pos must be initialized!
  160. # ...................................................................
  161. CreateImpactGlow:
  162.  
  163.     if ( b_hitThing == 1 )
  164.     {
  165.         t_glowImpact = CreateThingAtPos(tpl_laserHit, GetThingSector(t_victim), vec_pos, '0 0 0');
  166.     }
  167.     else
  168.     {
  169.         t_glowImpact = CreateThingAtPos(tpl_laserHit, GetThingSector(t_bullet), GetThingPos(t_bullet), '0 0 0');
  170.     }
  171.  
  172.     if ( t_glowImpact > -1 )
  173.     {
  174. #        f_beamTime = GetLifeLeft(t_bullet);
  175. #        SetLifeLeft(t_glowImpact, f_beamTime);
  176. #        MaterialAnim(mat_hit, 10, 1);
  177.  
  178. #        vec_dir = VectorSet( VectorX(vec_glowStartSize)* 0.5, VectorY(vec_glowStartSize) * 0.5, VectorZ(vec_glowStartSize) );
  179. #        vec_pos = VectorSet( VectorX(vec_glowEndSize)* 0.5, VectorY(vec_glowEndSize) * 0.5, VectorZ(vec_glowEndSize) );
  180. #        AnimateSpriteSize(t_glowImpact, vec_dir, vec_pos, f_beamTime);
  181.  
  182.         if ( b_hitThing == 1 )
  183.         {
  184.             AttachThingToThingEx(t_glowImpact, t_victim, 0x08);
  185.         }
  186.     }
  187.  
  188.     b_hitThing = 0;
  189.  
  190.     return;
  191.  
  192.  
  193. # ===================================================================
  194. end
  195.